package event;

import observer.ObservedList;
import observer.Copiable;

/**
 * This is for events in which an element is added to an {@link ObservedList}.
 *
 * @author Neil Dickson
 */
public class ListAddEvent<E extends Copiable> implements Undoable {
	private	ObservedList<E>	list;
	private	int				index;

	public ListAddEvent(ObservedList<E> list, int index) {
		this.list = list;
		this.index = index;
	}

	public Undoable undo() {
		E element = list.remove(index);
		// FIXME: Move the view to the location of the changed ObservedList.
		return new ListRemoveEvent<E>(list,element,index);
	}

	public String getDescription() {
		return "Adding "+list.get(index);
	}
}
